#pragma once
#include "InnerMath.hpp"
#include "Reference.hpp"

class Canvas : public Reference
{
public:
    Canvas();
    ~Canvas();

    void init(uint w, uint h, uint num_pbo = 2);

    void release();

    void render();

    void resize(uint w, uint h);

    inline int width() const { return _winW; }
    inline int height() const { return _winH; }
    inline int bytesPerPixel() const { return BytesPerPixel; }

    inline void dirty() { _dirty = true; }

    void* raw() { return &_data[0]; }

protected:

    static const uint BytesPerPixel;

    bool _valid = false;
    bool _dirty = false;

    int _winW = 800;
    int _winH = 600;
    uint _vbo = 0;
    uint _vao = 0;
    uint _tid = 0;
    uint _program = 0;
    uint _pboIndex = 0;
    std::vector<uint> _pbo;
    std::vector<unsigned char> _data;

};

